<?php
namespace Activity\Models;

class RedPacket extends Base
{
    public function initialize()
    {
        parent::initialize();
    }

    public function getSource()
    {
        return 'daishu_red_packet_config';
    }

    /**
     * 获取红包额度
     *
     * @return bool
     */
    public function getRedPacketLimit()
    {
        try {
            $query = $this->select('limit_money,valid_date')->from(self::class);
            $ret   = $query->getQuery()->execute()->toArray();
            if ($ret !== false && is_array($ret) && count($ret) > 0) {
                return $ret[0];
            }
        } catch (\PDOException $ex) {
            $this->errorLog('SELECT', $query->getPhql(), $ex->getMessage(), __FILE__, __LINE__);
        }
        return false;
    }

    /**
     * 获取红包余额
     *
     * @param $uid
     *
     * @return bool|mixed
     */
    public function getDeposit($uid)
    {
        try {
            $query = 'SELECT `money` FROM `daishu_red_packet_manage` WHERE `uid`=' . intval($uid);
            $ret   = $this->db()->query($query)->fetch();
            if ($ret !== false && is_array($ret) && count($ret) > 0) {
                return $ret;
            }
        } catch (\PDOException $ex) {
            $this->errorLog('SELECT', $query->getPhql(), $ex->getMessage(), __FILE__, __LINE__);
        }
        return false;
    }

}
